package com.xqx.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xqx.mapper.StudentMapper;
import com.xqx.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import com.xqx.service.StudentService;

import java.util.List;

/**
 * @author：xingquanxiang createTime：2019/10/26 15:17
 * description:
 */
@Service(interfaceClass = StudentService.class) //发布服务必须使用Dubbo提供的Service注解
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageInfo<Student> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Student> all = studentMapper.findAll();
        for (Student student : all) {
            System.out.println(student);
        }
        return new PageInfo<Student>(all);
    }

    @Override
    public Student doAdd(Student student) {
        studentMapper.add(student);
        return student.getId()!=null ? student : null;
    }

    @Override
    public boolean doEdit(Student student) {
        return studentMapper.edit(student)==1;
    }

    @Override
    public int doDel(long[] id) {
        return studentMapper.del(id);
    }

    @Override
    public Student findById(long id) {
        return studentMapper.findById(id);
    }

    @Override
    public boolean findByNameAndPassword(Student student) {
        return studentMapper.findByNameAndPassword(student)!=null;
    }
}
